package org.corespring.restaurant.web.controller;

import org.corespring.restaurant.model.Correo;
import org.corespring.restaurant.service.CorreoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class CorreoController {

	@Autowired
	private CorreoManager correoManager;
	
	@RequestMapping(value = "/correo.htm", method = RequestMethod.GET)
	public @ModelAttribute("correo")Correo verCorreo() {
		
		return new Correo();
	}

	@RequestMapping(value = "/correo.htm", method = RequestMethod.POST)
	public String enviarCorreo(@ModelAttribute("correo") Correo correo) {

		try {
			correoManager.sendMessage(correo, "");
			return "redirect:correo.htm";		
		} catch (Exception e) {

			return "correo";
		}
	}
}
